package com
{
	import com.assist.URI;
	import com.assist.view.LoadResponder;
	import com.haloer.data.OObject;
	import com.haloer.net.File;
	
	import flash.display.Stage;
	import flash.events.Event;

	public class ViewBase extends SuperBase
	{
		protected var _stage :Stage;
		protected var _ctrl:Controller;
		protected var _data:Data;
		protected var _lang:Lang;
		
		private var _assets:Object;
		private var _libs:Object;
		
		public function ViewBase( s :Stage )
		{
			super();
			
			_stage = s;
			_assets = new Object();
			_libs = new Object();
		}
		
		protected function createObject(param1:Class, param2:String = "") : Object
		{
			param2 = (param1 + "").replace(/View\]$/, "");
			return createObjectBase(param1, param2, this as View, _ctrl, _data);
		}
		
		public function init(data:Data, controller:Controller, lang:Lang) : void
		{
			this._data = data;
			this._ctrl = controller;
			this._lang = lang;
			//this._structure = Structure.getInstance(this._stage, this);
			_stage.addEventListener(Event.RESIZE, resetPosition);
		}
		
		protected function resetPosition(event:Event) : void {
			
		}
		
		public function hasAssets(url:String) : Boolean
		{
			return _assets[url];
		}
		
		public function getAssetsUrl(assetUrl:String) : String
		{
			if (hasAssets(assetUrl) == false)
			{
				throw new Error("对象 _assets 找不到键名为 " + assetUrl + " 的项。");
			}
			if (assetUrl.indexOf(URI.assetsUrl) == 0)
			{
				return assetUrl;
			}
			return URI.assetsUrl + _assets[assetUrl];
		}
		
		public function loadResources(list:Array, loadResponder:LoadResponder, isFullUrl:Boolean = false) : void {
			var tempList :Array = new Array();
			var len :uint = list.length;
			var i :uint = 0;
			while (i < len)
			{
				tempList[i] = isFullUrl ? (list[i]) : (getAssetsUrl(list[i]));
				i = (i + 1);
			}
			
			var callback :Function = function (arr:Array) : void
			{
				OObject.list(arr, _libs, list);
				loadResponder.lCallback();
			}
				
			var progress :Function = function (param1:int, param2:int, param3:int, param4:String) : void
			{
				loadResponder.lProgress(list[param2], param3, param2, param1, param4);
			}
				
			//File.loadList(tempList, callback, progress);
		}
	}
}